package com.helloscala.model

import org.squeryl.Schema

import yangbajing.persistence.SquerylEntrypoint._

object Entities extends Schema {
  val roles = table[MRole]("role_")

  val users = table[MUser]("user_")
  on(users)(entity =>
    declare(
      entity.email is(unique, indexed)
    ))

  val userPasswords = table[MUserPassword]("user_password_")

  val usersRoles = table[MUserRole]("user_role_")

  val topics = table[MTopic]("topic_")
  on(topics)(entity =>
    declare(
      entity.id is dbType("char(24)"),
      entity.slug is(unique, indexed),
      entity.content is dbType("text")
    ))

  val topicComments = table[MTopicComment]("topic_comment_")
  on(topicComments)(entity =>
    declare(
      entity.topic_id is dbType("char(24)")
    ))

  val tags = table[MTag]("tag_")
  on(tags)(entity =>
    declare(
      entity.ref_id is dbType("char(24)")
    ))

  val microChats = table[MMicroChat]("micro_chat_")
  on(microChats)(entity =>
    declare(
      entity.id is dbType("char(24)"),
      entity.content is dbType("text")
    ))

  val microChatReplys = table[MMicroChatReply]("micro_chat_reply_")
  on(microChatReplys)(entity =>
    declare(
      entity.id is dbType("char(24)")
    ))

  override def defaultLengthOfString: Int = 1024
}
